"""CreateOrderItemsTable Migration."""

from masoniteorm.migrations import Migration


class CreateOrderItemsTable(Migration):
    def up(self):
        """
        Run the migrations.
        """
        with create("order_items") as table:
            table.increments("id")
            table.integer("order_id").unsigned().comment("关联的订单ID")
            table.foreign("order_id").references("id").on("orders").on_delete("cascade")
            table.integer("service_id").unsigned().comment("商品ID")
            table.foreign("service_id").references("id").on("services")
            table.integer("service_scope_id").unsigned().comment("服务规范ID")
            table.foreign("service_scope_id").references("id").on("services_scopes")
            table.integer("quantity").comment("购买数量")
            table.decimal("price", 10, 2).comment("平方单价")
            table.decimal("total_price", 10, 2).comment("平方总价")
            table.timestamps()

    def down(self):
        """
        Revert the migrations.
        """
        self.schema.drop("order_items")
